#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<cstdlib>
#include<cmath>
#include<sstream>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<stack>
#define PI acos(-1)
#define MP make_pair
#define PB push_back
#define VI vector <int>
#define PII pair <int,int>
#define LL long long
#define SET(v,i) memset(v, i, sizeof(v))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define FORN(i,a,b) for (int i = (a); i < (b); i++)
#define DOWN(i,a,b) for (int i = (a); i > (b); i--)
#define FIT(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); it++)
#define FITD(it,v) for (typeof(v.rbegin()) it = v.rbegin(); it != v.rend(); it++)
using namespace std;
const int N=100005;
int a[N],s[N],n,one[N],two[N];
int main(){
	while(scanf("%d",&n)!=EOF){
		s[0]=0;
		for(int i=1;i<=n;i++)scanf("%d",&a[i]),s[i]=s[i-1]+a[i],one[i]=two[i]=0;
		if(s[n]%3){puts("0");continue;}
		int k=s[n]/3,c=0;
		for(int i=1;i<=n-1;i++){
			one[i]=one[i-1];
			if(s[i]==k)one[i]++;
			if(s[i]==k+k)two[i]=1;
			}
		LL ans=0;
		for(int i=2;i<n;i++)if(two[i])ans+=one[i-1];
		cout<<ans<<endl;
		}
    return 0;
    }
